DATAS SEGMENT
     inputer db 'please input twenty numbers: $'
     arraym db 60,0,60 dup(0)
     ;记住arrayp这两个是字型数据
     arrayp dw 40 dup('$')
     arrayn dw 40 dup('$')
     countne db 'the number of negative numbers is: $'
     posum db 'the sum of positive number is: $'
DATAS ENDS

STACKS SEGMENT
    db 100 dup(0)
STACKS ENDS

crlf macro
    mov dl,0ah
    mov ah,2
    int 21h
    mov al,0dh
    mov ah,2
    int 21h
endm

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
    
    lea dx,inputer
    mov ah,9
    int 21h

    lea dx,arraym
    mov ah,10
    int 21h

    crlf

    mov si,0
    mov bx,0
    mov di,0
    mov cx,0
isn:
    cmp arraym[si+2],20h
    jl exit
    cmp arraym[si+2],'-'
    jz negative
positive:
    call decibin
    xchg si,di
    mov arrayp[si],bx
    add si,2d  ;这里是先加的di
    xchg si,di
    jmp isn
negative:
    inc si
    call decibin
    xchg cx,si
    mov arrayn[si],bx
    add si,2d  ;这里是先加的cx
    xchg cx,si
    jmp isn

exit:
    mov bx,0
    mov cx,0
is$:
    cmp arrayn[bx],'$'
    jz nextp
    add bx,2d
    inc cx
    jmp is$

nextp:
    lea dx,countne
    mov ah,9
    int 21h
    add cx,30h
    mov dl,cl
    mov ah,2
    int 21h

    crlf

    lea dx,posum
    mov ah,9
    int 21h
    lea dx,outputer
    mov ah,9
    int 21h


fin:
    MOV AH,4CH
    INT 21H
;/******************************/
;子程序功能：输入cl转化为数字的asc码进行输出
outchar PROC near
    push ax
    push dx

    add cl,30h
    mov dl,cl
    mov ah,2
    int 21h

    pop dx
    pop ax
    ret
outchar ENDP

;/******************************/
;子程序功能：输入十进制转化为内存中的数据
;入口参数：arraym的内部数据
;返回值：输入的数字数据会储存在bx中，循环cx弹出
decibin PROC near
    push cx
    mov ax,0
    mov bx,0

newchar:
    mov al,arraym[si+2]
    cmp al,' '
    jz exit1
    cbw
    ;现在数字就在ax中
    xchg ax,bx
    mov cx,10d
    mul cx  ;乘十操作
    xchg ax,bx
    add bx,ax
    inc si
    jmp newchar

exit1:
    inc si
    pop cx
    ret
decibin ENDP

;/************************/
;子程序功能：内存中的数据以十六进制输出
;入口参数：输出的数据会储存在bx中
;返回值：void
binihex PROC near
    push cx
    mov ch,4

rotate:
    mov cl,4
    rol bx,cl
    mov al,bl
    and al,0fh
    add al,30h
    cmp al,3ah
    jl printit
    add al,7h

printit:
    mov dl,al
    mov ah,2
    int 21h
    dec ch
    jnz rotate

    pop cx
    ret
binihex ENDP

CODES ENDS
    END START